from functools import partial
import os
import argparse
import sys


dir_path=os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0,os.path.join(dir_path,'src'))
sys.path.insert(0,os.path.join(dir_path,'src/codeql_adapter'))
sys.path.insert(0,os.path.join(dir_path,'src/dataset_adapter'))


import codeql_tools.viewer.codeql_obj_factory as factory
import codeql_tools.config as config


path='result/test/ast-node.csv'
counter=set()
sources=list(factory.source_generate_from_csv(config.query_dir,config.codeql_database))

# for source in sources:

#     astnodes=list(source.iter_ast())
#     #tokens=list(source.iter_token())



#     for ast_node,_ in astnodes:
#         counter.add(ast_node.node_type)
        
# print(list(counter))



source=sources[0]
tokens=source.generate_tokens_for_nn()
nodes,edges=source.generate_ast_for_nn()

for i,block in source.iter_basic_block():
    block_tokens=source.get_basic_block_mapping_token(block)
    
    tokens_str=list(map(lambda x:x.string,block_tokens))
    
    if i<5:
        print(tokens_str)
        print('----------')
# for ast_type,v in nodes:
#     if len(v)!=len(set(v)):
#         print(v,[tokens[e] for e in v])
    #print(ast_type,v)
    
# print('-------')
    
# for e in edges:
#     print(e)